<?php
class Blog extends CI_Controller{
	public function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->model('entriesModel');
		$this->load->library('session');
	}

	function index(){
		if( ! $this->session->userdata('login_s'))
		{
			redirect('blog/add','refresh');
		}
		$data['query']=$this->entriesModel->getAllEntris();
			
		$this->load->view('blog_view',$data);
	}

	function add(){
		$this->load->view('blog_add_view');
	}

	function doAdd(){
		$id = $this->entriesModel->addEntries();

		$sess_data = array(
					'login_s' => True
		);
		$this->session->set_userdata($sess_data);

		redirect('blog/','refresh');
	}

	function update(){
		$id = $this->uri->segment(3);
		$data['query']=$this->entriesModel->getEntris($id);
		$this->load->view('blog_edit_view',$data);
	}

	function doUpdate(){
		$data=array(
				'title'=>$_POST['title'],
				'body'=>$_POST['body'], 
		);
		$id = $this->entriesModel->updateEntries($_POST['id'],$data);
			
		redirect('blog/update/'.$_POST['id'],'refresh');
	}

	function del(){
		$id = $this->uri->segment(3);
		$this->entriesModel->delEntris($id);
		redirect('blog/','refresh');
			
	}
	function login_out(){
		$this->session->sess_destroy();
		redirect('blog/','refresh');
	}
}
?>